﻿package org.display.graphic
{
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filesystem.File;
	import flash.text.TextField;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import flash.utils.Timer;
	
	import org.utils.ElementControl;
	import mx.controls.Alert

	public class ClassSquare extends Sprite
	{
		private var obj:Iv
		private var type:String
		private var eventName:String
		private var showName:String
		private var path:String
		public function ClassSquare(obj:Iv,type:String)
		{
			
			this.obj=obj
			this.type=type

			graphics.clear()
			graphics.lineStyle(1,0xcccccc,1)
			graphics.beginFill(0xACA899,1)
			graphics.drawEllipse(0,0,20,20)
			graphics.endFill()
				
				
			this.buttonMode=true
			this.useHandCursor=true

			this.addEventListener(MouseEvent.MOUSE_UP,mouseEvent)	
				
			this.addEventListener(MouseEvent.ROLL_OVER,mouseEvent)	
				
			this.addEventListener(MouseEvent.ROLL_OUT,mouseEvent)	
					
			eventName= obj.getViewName()
				
			path=obj.path
			
			path=path.replace("/xml/","/")
			
			var arr:Array=path.split("/")
			arr.pop()
			arr.push(type)
			
			if(type=="view"){
				
				arr.push(eventName+".as")	
				showName=eventName
				
			}else if(type=="viewProxy"){
				
				arr.push(eventName+"Proxy.as")
				showName=eventName+"Proxy"
			}
			if(type=="modelProxy"){
				
				arr.push(eventName.replace("View","Model")+"Proxy.as")
				showName=eventName.replace("View","Model")+"Proxy"
				
			}else if(type=="model"){
				
				arr.push(eventName.replace("View","Model")+".as")
				showName=eventName.replace("View","Model")
				
			}
			
			path=arr.join("/")
				 
		}
		
		public function createMenuItems(items:Array){
			
			var myContextMenu:ContextMenu = new ContextMenu();
			myContextMenu.hideBuiltInItems();
			
			for(var i=0;i<items.length;i++){
				
				createItem(items[i])
				
			}
			
			this.contextMenu = myContextMenu;
			
			function createItem(vlaue:String){
				
				var item:ContextMenuItem = new ContextMenuItem(vlaue);
				item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT ,menuselectEvent)
				myContextMenu.customItems.push(item);
				
			}
			
		}
		
		protected function menuselectEvent(e:ContextMenuEvent){
			
			switch(ContextMenuItem(e.currentTarget).caption){
				
				case "继承":

					break
				
				case "添加数据":
					
					break
				
			}
			
		}
		
		
		function mouseEvent(e:MouseEvent){
			
			switch(e.type){
				
			case MouseEvent.MOUSE_UP:
				
			trace(path)
			try{
				var file:File = File.desktopDirectory.resolvePath(path);
				file.openWithDefaultApplication();
			}catch(e:Error){Alert.show("路径不存在:"+path)}
			
			break
			
			case MouseEvent.ROLL_OVER:

			var tt:TextField=new TextField()
			tt.text = showName
			tt.border=true
			tt.autoSize="left"
			tt.background=true
			
			stage.addChild(tt)
			
			tt.x=stage.mouseX+20
			tt.y=stage.mouseY+20
			
			
			break
			
			
			case MouseEvent.ROLL_OUT:

			ElementControl.cleanObjByType(TextField,stage)
	
			break

			
			}
			

		}
		
		
		
	}
}